#!/usr/bin/perl

use strict;
use warnings;
use FindBin qw($Bin);
use File::Temp qw(tempdir);


chomp(my $cd = `git rev-parse --show-cdup`);
chdir("./$cd") || die $!;

my $tmpdir = tempdir(CLEANUP => 1);

my $version = `./csshX -v 2>&1` || die "Cauld not get version from csshX";

if ($version =~ /csshX\s+([\d.]+)(-\d+-\w+)?/) {
    $version = $1;
} else {
    die "Can't parse: $version";
}

print "Creating [csshX-$version.tgz]\n";

mkdir "$tmpdir/csshX-$version" || die "mkdir: $!";

open(MANIFEST, "< MANIFEST") || die "Can't read MANIFEST: $!";
while(defined(my $file = <MANIFEST>)) {
    chomp($file);
    system("cp", "$file", "$tmpdir/csshX-$version/") && die "copy $file: $!";
}
close(MANIFEST);

chdir $tmpdir || die "chdir: $!";
system("tar", "cvfz", "$tmpdir/csshX-$version.tgz", "csshX-$version") && die "tar: $!";

system("$Bin/googlecode_upload.py", "--summary", "csshX v$version", "--labels", "OpSys-OSX,Type-Archive", "--project", "csshx", "$tmpdir/csshX-$version.tgz")
   && die "Upload returned: $?";

print "Done.\n";

exit 0;

# vim: expandtab sw=4 ts=4 sts=4:

